package com.jsu.springboot_crop.service.impl;

import com.jsu.springboot_crop.dao.SellPurchaseDao;
import com.jsu.springboot_crop.entity.SellPurchase;
import com.jsu.springboot_crop.service.SellPurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Humura
 * @Date 2023/8/26 16:08
 * @Version 1.0
 */
@Service
public class SellPurchaseServiceImpl implements SellPurchaseService {
    @Autowired
    private SellPurchaseDao sellPurchaseDao;
    @Override
    public void add(SellPurchase sellPurchase) {
        sellPurchaseDao.insertSelective(sellPurchase);

    }

    @Override
    public List<SellPurchase> selectByName() {
        //获取用户名
        UserDetails principal = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String name = principal.getUsername();
        return sellPurchaseDao.selectByName(name);
    }
}
